#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
const int N = 1e6 + 10;
int p[N];
int n, m;
struct S
{
	int a, b;
	double w;
}s[N];
struct node
{
	int x, y, h;
}in[N];
double fun(node a, node b)
{
	return (double)sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) + (a.h - b.h) * (a.h - b.h);
}
double cmp(S a, S b)
{
	return a.w < b.w;
}
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
double kruskal()
{
	sort(s, s + m, cmp);
	for (int i = 1; i <= 1000; i++) {
		p[i] = i;
	}
	double ans = 0;
	for (int i = 0; i < m; i++) {
		int a = s[i].a;
		int b = s[i].b;
		a = find(a);
		b = find(b);
		if (a != b) {
			p[a] = b;
			ans += s[i].w;
		}
	}
	return ans;
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y, h;
		cin >> x >> y >> h;
		in[i] = { x,y,h };
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			double ans = fun(in[i], in[j]);
			s[m++] = { i + 1,j + 1,ans };
		}
	}
	double ans = kruskal();
	cout << fixed << setprecision(2) << ans << endl;
	return 0;
}